 <?php echo $javascript->link('jquery.selectboxes.min.js');  ?>
 <SCRIPT type=text/javascript>
	$(function() {
		$("#tabs").tabs().find(".ui-tabs-nav").sortable({axis:'x'});


	$('.comboChange').change(function() {
		
		var id = $(this)[0].id;
		var values = id.split("_");		
		var selectvalue= $('#'+id +' option:selected').val();			
		var comboSelected = values[3];
		 
		$.ajax({
	        type: "post",
	        url: "<?php echo $this->base?>/admin/ktmodels/getListRows/"+selectvalue,
	        data: selectvalue,
	        dataType: 'json',
	        success: function(response){ 
			$("#combo_row_id_"+comboSelected).removeOption(/./);
			//$("#combo_row_name_"+comboSelected).removeOption(/./);
			    $.each(response, function(i,item){	 
				    
				    var option = item;
					 $("#combo_row_id_"+comboSelected).addOption(option,option);
					// $("#combo_row_name_"+comboSelected).addOption(option,option);
					 
			    });
	        }
        
	        });   		 
		 	    
	});
	});
	</SCRIPT>

 <div class="kt-g1">
		<div class=" kt-right">
	   		<ul class="lst-tabs">
	   		   	<li id="icon-models" class="active"><a href="<?php echo $this->base.'/admin/ktmodels' ?>"><span class="icon"></span><?php __('models'); ?></a></li>	   					
				</ul>	  
		</div>
</div>
<div class="kt-md-content">
	<?php if (isset($configuration)){ ?>
		<div class="kt-md-configuracion">
			 	
			 	<div class="bd lst-form">
				 	  <table>
				 	  <tr>
					 	  <td> <p>  <strong> <?php __('configuration_name') ?> </strong></p>
					 	       <p> <?php echo $configuration["name"] ?></p>
					 	  </td>     
					 	  <td> 
					 	    <p> <strong><?php __('configuration_directory') ?> </strong></p>
					 	    <p> <?php echo $configuration["directory"] ?></p>
					 	  </td>	 	  
				 	  </tr>	 	  
				 	  </table> 
				</div>
		</div>
	 <?php } ?>
 <?php if (!is_writable(MODELS)) { ?>					
		  		<div class="kt-md  configuration_error">
		  		<div class="bd">
						<p class="error_msg"> <?php  __('Your directory  is NOT writable.'); ?> 
				  				<?php  __('generation  will not work correctly'); ?>
				 		</p> 
				 </div>
			 	</div>
<?php	} ?>
	 
<?php echo $form->create("Ktmodel", array('action' => 'admin_norender')); ?>
<div class="kt-md">
		<div class="hd"> 
			<h2>Generate Model from - <?php echo $name ?></h2>			
		</div>
	
<div class="bd">	
<div id="tabs">
   <ul>
      <li><a href="#tabs-1"> <?php __('validate_fields') ?></a></li>
      <li><a href="#tabs-2"> <?php __('hasMany') ?></a></li>
      <li><a href="#tabs-3"> <?php __('hasOne') ?></a></li>
      <li><a href="#tabs-4"> <?php __('belongsTo') ?></a></li>
      <li><a href="#tabs-5"> <?php __('hasAndBelongsToMany') ?></a></li>
   </ul>
  
      
 


 <div id="tabs-1">
	<div class="kt-md">
		<div class="hd">
		<h3><?php __('validate_fields') ?></h3>
		<h5><?php __('validate_fields_legend') ?></h5>
		</div>			
		<div class="bd">	
				
			<div class="lst-form kt-md-group">	
			<table>
				<tr class="form-field">
					<th> <?php __('field_name') ?> </th>
					<th> <?php __('database_type') ?> </th>
					<th> <?php __('validate_type') ?> </th>				
				</tr>
				
				<?php foreach ($fields as $field){ ?>
				<tr class="form-field">
					<td><?php echo $form->label("valid][".$field['name'], $field['name']); ?></td>
					<td><?php echo $field['type']; ?></td>
					<td><?php echo $form->select("valid][".$field['name'], $selector ,  null, false); ?></td>				
				</tr>			
				<?php } ?>			
			</table>			 		
			</div>						
		</div>		
	</div>
		<div class="kt-md">
		<div class="hd">
		<h3><?php __('tablename_bd') ?></h3>
		<h5><?php __('tablename_bd_legend') ?></h5>
		</div>			
		<div class="bd">			
			<div class="lst-form kt-md-group">	
			<table>
				<tr class="form-field">
					<td><?php echo $form->input("tablename]", array('label' => __('tablename',true) )); ?></td>
				</tr>		
			</table>			 		
			</div>						
		</div>		
	</div>
</div>	
 <div id="tabs-2">	
	<div class="kt-md">	
		<div class="hd">
		<h3><?php __('hasMany') ?></h3> 
		<h5><?php __('hasMany_legend') ?> </h5>
		</div>	
		<div class="bd">			
			<div class="lst-form kt-md-group">
			<table>
			  <tr class="form-field">			    
				  <td><?php echo $form->input("hasMany][0][alias]", array('label' => __('relation_alias',true) )); ?></td>
				  <td><?php echo $form->input("hasMany][0][className]", array("type" => "select", "label"=>__('className',true), "options"=>$selectTables, "empty"=>true)); ?></td>
			 	  <td><?php echo $form->input("hasMany][0][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true),  "options"=>$selectModelsField, "empty"=>true)); ?></td>		
	
				  
			  </tr>
			  <tr class="form-field">			     
				  <td><?php echo $form->input("hasMany][1][alias]", array('label' => __('relation_alias',true) )); ?></td>
			 	  <td><?php echo $form->input("hasMany][1][className]", array("type" => "select", "label"=>__('className',true), "options"=>$selectTables, "empty"=>true)); ?></td>
			 	  <td><?php echo $form->input("hasMany][1][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true),  "options"=>$selectModelsField, "empty"=>true)); ?></td>		
	 		 </tr>
			  <tr class="form-field">			   
				  <td><?php echo $form->input("hasMany][2][alias]", array('label' => __('relation_alias',true) )); ?></td>
				  <td><?php echo $form->input("hasMany][2][className]", array("type" => "select", "label"=>__('className',true), "options"=>$selectTables, "empty"=>true)); ?></td>
			 	  <td><?php echo $form->input("hasMany][2][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true),  "options"=>$selectModelsField, "empty"=>true)); ?></td>		
	  		  </tr>
			  <tr class="form-field">			  
				  <td><?php echo $form->input("hasMany][3][alias]", array('label' => __('relation_alias',true) )); ?></td>
				  <td><?php echo $form->input("hasMany][3][className]", array("type" => "select", "label"=>__('className',true), "options"=>$selectTables, "empty"=>true)); ?></td>
			 	  <td><?php echo $form->input("hasMany][3][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true),  "options"=>$selectModelsField, "empty"=>true)); ?></td>		
	 
			  </tr>
			</table>	
			 	
			</div>						
		</div>	
		<div class="ft">
				<p><strong><?php __('alias') ?></strong> <?php __('alias_legend') ?> </p>
			    <p><strong><?php __('className') ?></strong> <?php __('className_legend_hasMany') ?> </p>
			    <p><strong><?php  __('foreignKey') ?></strong>  <?php __('foreignKey_legend_hasMany') ?> </p>		
		</div>	
	</div>
</div>
 <div id="tabs-3">	
	<div class="kt-md">	
		<div class="hd">
		<h3><?php __('hasOne') ?></h3>

		<h5><?php __('hasOne_title') ?></h5>
		</div>	
		<div class="bd">			
			<div class="lst-form kt-md-group"> 
			<table>
			  <tr class="form-field">
			  	<td><?php echo $form->input("hasOne][0][alias]", array('label' =>  __('relation_alias',true))); ?></td>			 
			    <td> <?php echo $form->input("hasOne][0][className]", array("type" => "select", "label"=>__('className',true), "class"=>"comboChange", "id" =>"combo_row_table_1" ,"options"=>$selectTables, "empty"=>true)); ?></td>
				<td> <?php echo $form->input("hasOne][0][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true), "id" =>"combo_row_id_1" ,"options"=>"", "empty"=>false)); ?>
			  </tr>
			   <tr class="form-field">
			  	<td><?php echo $form->input("hasOne][1][alias]", array('label' =>  __('relation_alias',true))); ?></td>			 
			    <td> <?php echo $form->input("hasOne][1][className]", array("type" => "select", "label"=>__('className',true), "class"=>"comboChange", "id" =>"combo_row_table_2" ,"options"=>$selectTables, "empty"=>true)); ?></td>
				<td> <?php echo $form->input("hasOne][1][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true), "id" =>"combo_row_id_2" ,"options"=>"", "empty"=>false)); ?>
			  </tr>
			   <tr class="form-field">
			  	<td><?php echo $form->input("hasOne][2][alias]", array('label' =>  __('relation_alias',true))); ?></td>			 
				 <td> <?php echo $form->input("hasOne][2][className]", array("type" => "select", "label"=>__('className',true), "class"=>"comboChange", "id" =>"combo_row_table_3" ,"options"=>$selectTables, "empty"=>true)); ?></td>
				<td> <?php echo $form->input("hasOne][2][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true), "id" =>"combo_row_id_3" ,"options"=>"", "empty"=>false)); ?>
		     </tr>
			   <tr class="form-field">
			  	<td><?php echo $form->input("hasOne][3][alias]", array('label' =>  __('relation_alias',true))); ?></td>			 
			  	<td> <?php echo $form->input("hasOne][3][className]", array("type" => "select", "label"=>__('className',true), "class"=>"comboChange", "id" =>"combo_row_table_4" ,"options"=>$selectTables, "empty"=>true)); ?></td>
				<td> <?php echo $form->input("hasOne][3][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true), "id" =>"combo_row_id_4" ,"options"=>"", "empty"=>false)); ?>

			  </tr>
			</table> 
			</div>	 
		</div>	
		<div class="ft">
			   <p><strong><?php __('alias') ?></strong> <?php __('alias_legend') ?> </p>
			   <p><strong><?php  __('className') ?></strong>   <?php __('className_legend_hasOne') ?></p>
			   <p><strong><?php __('foreignKey') ?>:</strong> <?php __('foreignKey_legend_hasOne') ?> </p>
		</div>		
	</div>
</div>
 <div id="tabs-4">	
	<div class="kt-md">	
		<div class="hd">
		<h3> <?php __('belongsTo') ?> </h3>

		<h5> <?php __('belongsTo_legend') ?></h5>
		</div>	
		<div class="bd">			
			<div class="lst-form kt-md-group">
			<table>
			  <tr class="form-field">
				  <td><?php echo $form->input("belongsTo][0][alias]", array('label' => __('relation_alias',true))); ?></td>			 
			 	  <td><?php echo $form->input("belongsTo][0][className]", array("type" => "select", "label"=>__('className',true), "options"=>$selectTables, "empty"=>true)); ?></td>
			 	  <td><?php echo $form->input("belongsTo][0][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true),  "options"=>$selectModelsField, "empty"=>true)); ?></td>		
			  </tr>
			  
			   <tr class="form-field">
				  <td><?php echo $form->input("belongsTo][1][alias]", array('label' => __('relation_alias',true))); ?></td>			 
				  <td><?php echo $form->input("belongsTo][1][className]", array("type" => "select", "label"=>__('className',true), "options"=>$selectTables, "empty"=>true)); ?></td>
			 	  <td><?php echo $form->input("belongsTo][1][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true),  "options"=>$selectModelsField, "empty"=>true)); ?></td>
			  </tr>
			   <tr class="form-field">
				  <td><?php echo $form->input("belongsTo][2][alias]", array('label' => __('relation_alias',true))); ?></td>			 
				  <td><?php echo $form->input("belongsTo][2][className]", array("type" => "select", "label"=>__('className',true), "options"=>$selectTables, "empty"=>true)); ?></td>
			 	  <td><?php echo $form->input("belongsTo][2][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true),  "options"=>$selectModelsField, "empty"=>true)); ?></td>
			  </tr>
			   <tr class="form-field">
				  <td><?php echo $form->input("belongsTo][3][alias]", array('label' => __('relation_alias',true))); ?></td>			 
				  <td><?php echo $form->input("belongsTo][3][className]", array("type" => "select", "label"=>__('className',true), "class"=>"", "options"=>$selectTables, "empty"=>true)); ?></td>
			   	  <td><?php echo $form->input("belongsTo][3][foreignKey]", array("type" => "select", "label"=>__('foreignKey',true),  "options"=>$selectModelsField, "empty"=>true)); ?></td>
			  </tr>
			</table>	
			</div>						
		</div>	
		<div class="ft">
			   <p><strong><?php __('alias') ?></strong> <?php __('alias_legend') ?> </p>
			   <p><strong><?php __('className') ?> :</strong> <?php __('className_legend_belongsTo') ?></p>
			   <p><strong><?php __('foreignKey') ?>: </strong><?php  __('foreignKey_legend_belongsTo') ?> </p>
		</div>			
	</div>
</div>
 <div id="tabs-5">	
	<div class="kt-md">	
		<div class="hd">
		<h3><?php __('hasAndBelongsToMany') ?></h3>

		<h5><?php __('hasAndBelongsToMany_legend') ?></h5>
		</div>	
		<div class="bd">			
			<div class="lst-form kt-md-group">	
			 
			<table>
			  <tr class="form-field">
			     <td>
			     	<?php echo $form->input("hasAndBelongsToMany][alias]", array('label' => __('model_alias_relation',true))); ?>
			     	<p><strong><?php __('model_alias_relation_legend')?></strong>:<?php  __('model_alias_relation_legend') ?>  </p>
			     </td>
			  </tr>
			  
			 <tr class="form-field">
			  	<td>
			  	   <?php echo $form->input("hasAndBelongsToMany][className]",array('label' => __('className',true))); ?>
			  	   <p><strong><?php  __('className') ?>:</strong><?php  __('className_legend') ?> </p>
			 	</td>
			  </tr>	
			  
			 <tr class="form-field"> 
				<td>
				  <?php echo $form->input("hasAndBelongsToMany][joinTable]",array('label' => __('joinTable',true))); ?>
				  <p><strong><?php  __('joinTable') ?>:</strong>   <?php  __('joinTable_legend') ?></p>
				 </td>
			  </tr>
			  <tr class="form-field"> 
				 <td>
				 	<?php echo $form->input("hasAndBelongsToMany][foreignKey]",array('label' =>  __('foreignKey',true))); ?>
				  	<p> <strong><?php  __('foreignKey') ?>: </strong><?php  __('foreignKey_legend') ?> </p>
				  </td>
			  </tr>
			  <tr class="form-field"> 
				 <td>
				 	 <?php echo $form->input("hasAndBelongsToMany][associationForeignKey]",array('label' =>  __('associationForeignKey',true))); ?>
				 	 <p><strong> <?php __('associationForeignKey') ?>: </strong> <?php __('associationForeignKey_legend') ?> </p>
				  </td>
			  </tr>
			</table>
			 		
			</div>						
		</div>		
	</div>
</div>
</div> <!-- fin tabs -->	
	
	<?php echo $form->input('names', array('type' => 'hidden','value' => $name));?> 
	<?php echo $form->input('useDbConfig', array('type' => 'hidden','value' => $userDbConfig));?> 
	<p class="submit"><?php echo $form->submit(__('generate',true)) ?></p>		
	<?php echo $form->end();?>
</div>	
</div>	
</div>